<?
$total = $this->total;
$ads = $this->ads;
$dateFormat = 'Y-m-d';
$categories = $this->categories; // все рубрики
$category = $this->category; // текущая рубрика или null
?>

<div class="content-box">

    <div class="content-box-header">
        <h3>Объявления</h3>
        <ul class="content-box-tabs">
            <li><a class="default-tab" href="#tab1">Таблица</a></li>
        </ul>
        <div class="clear"></div>
    </div>
    <div class="content-box-content">
        <div class="tab-content default-tab" id="tab1">
            <a href="/admin/statistic/ad">Очистить фильтры</a>
            Всего: <?= $total ?>

            За промежуток времени:
            <form action="" method="post">
                <input type="text" name="dateStart" value="<?= $this->dateStart ?>" class="datepicker">-
                <input type="text" name="dateEnd" value="<?= $this->dateEnd ?>" class="datepicker">

                Рубрика:
                <select name="category">
                    <option value="">Любая</option>
                    <? foreach ($categories as $record): ?>

                        <option value="<?= $record['id'] ?>" <?= $category == $record['id'] ? 'selected' : false ?>>
                            <?= $this->escape($record['name']); ?>
                        </option>
                    <? endforeach; ?>
                </select>
                <input type="submit" value="Применить">
            </form>

            <table class="table table-stripted">
                <thead>
                <tr>
                    <th>#</th>
                    <th>Содержание</th>
                    <th>Автор</th>
                    <th>Дата создания</th>
                    <th>Рубрика</th>
                </tr>
                </thead>
                <tbody>
                <? foreach ($ads as $ad): ?>
                <tr>
                    <td><?= $ad['id'] ?></td>
                    <td><?= $this->escape($ad['content']); ?></td>
                    <td><?= $this->escape($ad['author']); ?></td>
                    <td><?= $ad['date']->format($dateFormat) ?></td>
                    <td>
                        <form action="" method="post">
                            <input type="hidden" name="category" value="<?= $ad['subCat']['category']['id'] ?>">
                            <input type="submit" value="<?= $ad['subCat']['category']['name'] ?>">
                        </form>

                        <form action="" method="post">
                            <input type="hidden" name="subCat" value="<?= $ad['subCat']['id'] ?>">
                            <input type="submit" value="<?= $ad['subCat']['name'] ?>">
                        </form>
                    </td>
                </tr>
                    <? endforeach; ?>
                </tbody>
            </table>
            <?= $this->partial('/paginator/common.phtml', array('paginator' => $this->paginator)) ?>
        </div>
    </div>
</div>